package com.ice.cloud.payManagement.service.impl;

import com.ice.cloud.comm.resp.R;
import com.ice.cloud.comm.resp.ReturnCodeEnum;
import com.ice.cloud.payManagement.db.dao.AccountMapper;
import com.ice.cloud.payManagement.db.entities.AccountEntity;
import com.ice.cloud.payManagement.service.AccountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class AccountServiceImpl implements AccountService {
    @Autowired
    AccountMapper accountMapper;
    @Override
    public R<String> feeDeduction(Integer id, Double money) {
        AccountEntity entity = accountMapper.getById(id);
        if(entity == null){
            return  R.error(ReturnCodeEnum.RC404.getCode(), "账户为空");
        }
        if((entity.getBalance()-money<0)){
           return  R.error(ReturnCodeEnum.RC999.getCode(), "余额不足");
        }
        entity.setBalance(entity.getBalance()-money);
        accountMapper.updateBalance(entity);
        return R.success("ok");

    }
}
